<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="亚马逊订单id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amzOrderId">
              <a-input v-model="model.amzOrderId" placeholder="请输入亚马逊订单id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="店铺id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="storeId">
              <j-dict-select-tag type="list" v-model="model.storeId" dictCode="hz_store_auth_amazon,name,id" placeholder="请选择店铺id" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="卖家订单id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sellerOrderId">
              <a-input v-model="model.sellerOrderId" placeholder="请输入卖家订单id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="系统订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderStatus">
              <a-input v-model="model.orderStatus" placeholder="请输入系统订单状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发货状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shipmentStatus">
              <a-input v-model="model.shipmentStatus" placeholder="请输入发货状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="市场id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="marketplaceId">
              <a-input v-model="model.marketplaceId" placeholder="请输入市场id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发货方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryWay">
              <a-input v-model="model.deliveryWay" placeholder="请输入发货方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderType">
              <a-input v-model="model.orderType" placeholder="请输入订单类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="ioss" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ioss">
              <a-input v-model="model.ioss" placeholder="请输入ioss"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="eori" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="eori">
              <a-input v-model="model.eori" placeholder="请输入eori"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="税号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxNum">
              <a-input v-model="model.taxNum" placeholder="请输入税号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditTime">
              <j-date placeholder="请选择审核时间" v-model="model.auditTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发货时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryTime">
              <j-date placeholder="请选择发货时间" v-model="model.deliveryTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="付款方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentMethod">
              <a-input v-model="model.paymentMethod" placeholder="请输入付款方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="承诺发货开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="earliestShipDate">
              <j-date placeholder="请选择承诺发货开始时间" v-model="model.earliestShipDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="承诺发货结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="latestShipDate">
              <j-date placeholder="请选择承诺发货结束时间" v-model="model.latestShipDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="承诺交付开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="earliestDeliveryDate">
              <j-date placeholder="请选择承诺交付开始时间" v-model="model.earliestDeliveryDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="承诺交付结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="latestDeliveryDate">
              <j-date placeholder="请选择承诺交付结束时间" v-model="model.latestDeliveryDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'AmzOrderInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/order/amzOrderInfo/add",
          edit: "/order/amzOrderInfo/edit",
          queryById: "/order/amzOrderInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>